package com.longge;

import java.util.HashMap;
import java.util.Map;

/**
 * @创建人 xinglongge
 * @创建时间 2021/11/23
 * @描述
 */
public class IsAnagram {

    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) return false;
        char[] sChars = s.toCharArray();
        char[] tChars = t.toCharArray();
        Map<Character, Integer> sMap = new HashMap<>();
        for (char sChar : sChars) {
            sMap.put(sChar, sMap.getOrDefault(sChar, 0) + 1);
        }
        for (char tChar : tChars) {
            int num = sMap.getOrDefault(tChar, 0) - 1;
            if (num == -1) return false;
            sMap.put(tChar, num);
        }
        return true;
    }
}
